//{$CLEO .lm}
// head.lm
{$CLEO}
const
fone = 0x858624
end

audiostream.Load3D(11@, "Audio\sfx\HONDA_LAMP_START.wav")
audiostream.Load3D(12@, "Audio\sfx\HONDA_LAMP_END.wav")

// disable 3d primitive effect
0a8c: 0x6A2ED3 12 0x90 1
0a8c: 0x6A2EEB 12 0x90 1
0A8C: 0x6BDE73 18 0x90 1

0a8c: 0x6E16A9 2 0x9090 1 //  - ,      
// br
0a8c: 0x6E1553 2 {0xC1D8} 0x9090 1 // width
0A8C: 0x70C68A 2 0x9090 1

0A8C: 0x70C69A 1 0xEB 1 //   NPC    ,    

//0A8C: 0x70C6A9 4 0 1 //    NPC      
0A8C: 0x6E151D 1 0xFC 1 //       _texHeadlight
//0a8c: 0x6E151D 4 0xC40404 1
//0a8c: 0x70C72D 4 0x80 1 // intensity, main headlight
//0a8c: 0x70C6CB 4 0x80 1 // intensity, main headlight 2

//0a8c: 0x6E0CEC 1 3 1 // reflective
//0a8c: 0x6E0DE2 1 3 1 // reflective//headlight corona radius

{
28@ = 0.0
0AC7: 31@ = var 28@ offset
//0a8c: 0x6E0C35 4 31@ 1
0a8c: 0x6E16D7 4 31@ 1
}

//  / 
0a8c: 0x70C58F 4 0x90909090 1
0a8c: 0x70C593 2 0x9090 1
0a8c: 0x70C5D2 4 0x90909090 1
0a8c: 0x70C5D6 2 0x9090 1

//change headlight size
//0AC6: 0@ = label @label offset
0A9F: 0@ = current_thread_pointer 
0@ += 0x10 
0A8D: 0@ = read_memory 0@ size 4 virtual_protect 0 
0@ -= @label
0a8c: 0@ 4 16.0 0
0a8c: 0x6E16A3 4 0@ 1
0A9F: 0@ = current_thread_pointer 
0@ += 0x10 
0A8D: 0@ = read_memory 0@ size 4 virtual_protect 0 
0@ -= @label3
0a8c: 0@ 4 16.0 0
0a8c: 0x6E1537 4 0@ 1
0A9F: 0@ = current_thread_pointer 
0@ += 0x10 
0A8D: 0@ = read_memory 0@ size 4 virtual_protect 0 
0@ -= @label4
0a8c: 0@ 4 8.0 0
0a8c: 0x6E1548 4 0@ 1
//FIX HEADREFLECT CORONA ALPHA
//0a8c: 0x6E0DEE 1 128 1
// change Y offset of headlight
//0AC6: 0@ = label2 @label offset
0A9F: 0@ = current_thread_pointer 
0@ += 0x10 
0A8D: 0@ = read_memory 0@ size 4 virtual_protect 0 
0@ -= @label2
0a8c: 0@ 4 0.35 0
0a8c: 0x6E16B1 4 0@ 1
0a8c: 0x6E1559 4 0@ 1

// headlight inject for automobiles
//0AC6: 31@ = label @__asm offset
0A9F: 31@ = current_thread_pointer 
31@ += 0x10 
0A8D: 31@ = read_memory 31@ size 4 virtual_protect 0 
31@ -= @__asm  
//0AC6: 30@ = label @__jmp offset
0A9F: 30@ = current_thread_pointer 
30@ += 0x10 
0A8D: 30@ = read_memory 30@ size 4 virtual_protect 0 
30@ -= @__jmp 
0AB1: call_scm_func @define_jump_to_asm_inj 4 asm_inj 31@ jump_from 0x70C70B then_jump 0x70C72C offset_jump_in_asm 30@
//0AC6: 31@ = label @__asm offset
0A9F: 31@ = current_thread_pointer 
31@ += 0x10 
0A8D: 31@ = read_memory 31@ size 4 virtual_protect 0 
31@ -= @__asm2  
//0AC6: 30@ = label @__jmp offset
0A9F: 30@ = current_thread_pointer 
30@ += 0x10 
0A8D: 30@ = read_memory 30@ size 4 virtual_protect 0 
30@ -= @__jmp2 
0AB1: call_scm_func @define_jump_to_asm_inj 4 asm_inj 31@ jump_from 0x6E27B2 then_jump 0x6E27B7 offset_jump_in_asm 30@

while true
    wait 0
    if
        player.Defined(0)
    then
        if
            actor.Driving($3)
        then
            while true
                wait 0
                if
                    not player.Defined(0)
                then
                    break
                else if
                        not actor.Driving($3)
                    then
                        break
                    end
                end
                if
                    0AB0: 71
                then
                    //0AC6: 31@ = label @__asm offset
                    0A9F: 31@ = current_thread_pointer 
                    31@ += 0x10 
                    0A8D: 31@ = read_memory 31@ size 4 virtual_protect 0 
                    31@ -= @__asm
                    31@ += 0xE
                    0A8C: 31@ 1 0xFC 0
                    
                    0A9F: 31@ = current_thread_pointer 
                    31@ += 0x10 
                    0A8D: 31@ = read_memory 31@ size 4 virtual_protect 0 
                    31@ -= @__asm2
                    31@ += 21
                    0A8C: 31@ 4 35.0 0 
                    
                    0A8D: 8@ = read_memory 0xBA6797 size 1 virtual_protect false
                    0093: 8@ = integer 8@ to_float
                    div(8@, 64.0)
                    audiostream.PerformAction(11@, PLAY)
                    audiostream.Volume(11@) = 8@
                    
                    0811: 8@ $3
                    audiostream.LinkToCar(11@, 8@)
                    
                    while 0AB0: 71
                        wait 0
                        if
                            not player.Defined(0)
                        then
                            goto @break
                        else if
                                not actor.Driving($3)
                            then
                                goto @break
                            end
                        end
                    end
                    while 8AB0: 71
                        wait 0
                        if
                            not player.Defined(0)
                        then
                            goto @break
                        else if
                                not actor.Driving($3)
                            then
                                goto @break
                            end
                        end
                    end
                    //0AC6: 31@ = label @__asm offset
                    0A9F: 31@ = current_thread_pointer 
                    31@ += 0x10 
                    0A8D: 31@ = read_memory 31@ size 4 virtual_protect 0 
                    31@ -= @__asm
                    31@ += 0xE
                    0A8C: 31@ 1 0xF8 0
                    
                    0A9F: 31@ = current_thread_pointer 
                    31@ += 0x10 
                    0A8D: 31@ = read_memory 31@ size 4 virtual_protect 0 
                    31@ -= @__asm2
                    31@ += 21
                    0A8C: 31@ 4 20.0 0
                    
                    0A8D: 8@ = read_memory 0xBA6797 size 1 virtual_protect false
                    0093: 8@ = integer 8@ to_float
                    div(8@, 64.0)
                    audiostream.PerformAction(12@, PLAY)
                    audiostream.Volume(12@) = 8@
                    
                    0811: 8@ $3
                    audiostream.LinkToCar(12@, 8@)
                                  
                    while 0AB0: 71
                        wait 0
                        if
                            not player.Defined(0)
                        then
                            goto @break
                        else if
                                not actor.Driving($3)
                            then
                                goto @break
                            end
                        end
                    end
                end
            end
        end
    end
    continue
    :break
    //0AC6: 31@ = label @__asm offset
    0A9F: 31@ = current_thread_pointer 
    31@ += 0x10 
    0A8D: 31@ = read_memory 31@ size 4 virtual_protect 0 
    31@ -= @__asm
    31@ += 0xE
    0A8C: 31@ 1 0xF8 0
end

:label
hex
    00 00 00 00
end

:label2
hex
    00 00 00 00
end

:label3
hex
    00 00 00 00
end

:label4
hex
    00 00 00 00
end

:__asm
hex
 74 0B // jz +B
 A1 F8 03 C4 00 // mov eax, [0xC403F8]
 89 44 24 2C // mov [esp+1C+arg_8], eax
 EB 09 // jmp +9
 // +B
 A1 F8 03 C4 00 // mov eax, [0xC403FC] // for player
 89 44 24 2C // mov [esp+1C+arg_8], eax
 // + 9
 8B 44 24 44 
 6A 00
 68 00 00 80 3F
 6A 00 
 68 00 00 C0 40
 68 30 00 00 00
 8B 4C 24 54
 68 30 00 00 00
 8B 54 24 54
 68 30 00 00 00
 8B 44 24 54
end
 
:__jmp 
hex 
    E9 00 00 00 00 // jmp 0 
end

:__asm2
hex
 50 // push eax
 6A 00 6A FF // push 0; push -1
 B8 D0 E0 56 00 // mov eax, 0x56E0D0
 FF D0 // call eax
 83 C4 08 // add esp, 8
 3B F0 // cmp esi, eax
 58 // pop eax
 75 07 // jnz +7
 68 00 00 A0 41 // push fPlayer
 EB 05 // jmp +5
 68 00 00 A0 41 // push 20.0  // 35 = 0x420C0000 20 = 0x41A00000
end
 
:__jmp2 
hex 
    E9 00 00 00 00 // jmp 0 
end

:define_jump_to_asm_inj 
0A8C: write_memory 1@ size 1 value 0xE9 virtual_protect 1 
0085: 4@ = 1@ 
4@ += 5 
0062: 0@ -= 4@ 
1@ += 1 
0A8C: write_memory 1@ size 4 value 0@ virtual_protect 1 
0085: 4@ = 3@ 
4@ += 5 
0062: 2@ -= 4@ 
3@ += 1 
0A8C: write_memory 3@ size 4 value 2@ virtual_protect 1 
0AB2: ret 0